import Worker from './db.worker.js'

import BaseWorker from './base'

class EleWorker extends BaseWorker {
  constructor() {
    super(new Worker())
  }

  insert(params) {
    this.postMessage('INSERT', params)
  }

  query(timestamp) {
    return new Promise(resolve => {
      let success = null
      this.once('QUERY_RESULT', ({ data }) => {
        success = true

        resolve(data)
      })

      setTimeout(() => {
        if (!success) resolve(null)
      }, 50)

      this.postMessage('QUERY', timestamp)
    })
  }
}

export default new EleWorker()
